//
//  GSSubscribeViewController.m
//  GameSky
//
//  Created by lanou on 16/1/10.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSSubscribeViewController.h"
#import "GSSubscribeViewController_Add.h"
#import "GSSubscribeViewController_Add_Topic_Details.h"
#import "GSSubscribeViewController_Add_Topic_Details_Cell.h"
#import "GSSubscrebe_Add_Topic_Details.h"
#import "GSSubscrebe_Add_Topic.h"
#import "GSArticleViewController.h"
#import "GSSearchViewController.h"
@interface GSSubscribeViewController () <UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
/**
 * UI
 */
// titleView
@property (nonatomic, strong) UIView *titleView;
// 订阅内容 按钮
@property (nonatomic, strong) UIButton *subscribeContentButton;
// 订阅专题 按钮
@property (nonatomic, strong) UIButton *subscribeSubjectButon;
// 展示页面 scrollView
@property (nonatomic, strong) UIScrollView *scrollView;
// 展示页面 --tabelView
@property (nonatomic, strong) UITableView *subscribeContentTableView;
@property (nonatomic, strong) UITableView *subscribeSubjectTableView;

/**
 * 标签动态改变大小
 */
// 保存 刚要拖拽时的点
@property (nonatomic, assign) CGFloat x;

// 判断 滑动的点坐标
@property (nonatomic, assign) NSInteger y;


// 保存 变大的 标签tag
@property (nonatomic, assign) NSInteger numTag;

/**
 * 数据库
 */
@property (nonatomic, strong) FMDatabase *db;
// 数据库 字符串数组 : (只提取的 ID的字符串, 数据请求使用)
@property (nonatomic, strong) NSMutableArray *dataArray;
// 数据库 中model的数组 (跳转到下一界面时,可以 移除(添加)到数据库)
@property (nonatomic, strong) NSMutableArray *modelArray;
/**
 * 界面展示 数据,
 */
// 数据请求,起始 index----------订阅内容界面
@property (nonatomic, assign) NSInteger startIndexContent;

// 订阅内容
@property (nonatomic, strong) NSMutableArray *subscribeContentTableViewListArray;
// 订阅专题
@property (nonatomic, strong) NSMutableArray *subscribeSubjectTableViewListArray;

@end

@implementation GSSubscribeViewController
#pragma mark----------视图将要出现----------
- (void)viewWillAppear:(BOOL)animated{
    
    _startIndexContent = 1;
    // 解析数据,刷新界面
    // 从数据库拿出数据
    [self getDataFromDB];
    // 清楚 数组 元素
    [self.subscribeContentTableViewListArray removeAllObjects];
    [self.subscribeSubjectTableViewListArray removeAllObjects];
    [self setUpSubscribeContentTableViewData];
    [self setUpSubscribeSubjectTableViewData];
}

#pragma mark--------------视图加载完成-----------------------
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

// 设置导航栏
    [self setUpNavigationBar];
// 添加scrollView
    
    [self addScrollView];
// scrollView 添加子视图
    [self addSubviewsOnScrollView];
// 默认 视图刚一出现,订阅内容的标签就变大
    _numTag = 100;
}
#pragma mark----------------导航栏设置--------------------
- (void)setUpNavigationBar{
    CGFloat titleViewX = kScreenWidth / 20 * 3;
    CGFloat titleViewWidth = kScreenWidth - 2 * titleViewX;
    // navigationBar 添加右侧按钮
    
    [self.navBar.rightButton addTarget:self action:@selector(rightAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navBar.rightButton setImage:[UIImage imageNamed:@"common_Icon_AddButton_20x20_UIMode_Day@2x"] forState:(UIControlStateNormal)];
    
// 设置titleView
   _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.navBar.titleScrollView.width, self.navBar.titleScrollView.height)];
    //_titleView.backgroundColor = [UIColor yellowColor];
    [self.navBar.titleScrollView addSubview:_titleView];
// 订阅内容button
    _subscribeContentButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _subscribeContentButton.frame = CGRectMake(titleViewWidth / 9, 0, (titleViewWidth - titleViewWidth / 9 * 2 - 15) / 2, _titleView.height);
    [_subscribeContentButton setTitle:@"订阅内容" forState:(UIControlStateNormal)];
    // 添加点击方法
    [_subscribeContentButton addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    // 添加tag
    _subscribeContentButton.tag = 100;
    //_subscribeContentButton.backgroundColor = [UIColor purpleColor];
    [_subscribeContentButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    _subscribeContentButton.titleLabel.font = [UIFont boldSystemFontOfSize:14 * 1.4];
    [_titleView addSubview:_subscribeContentButton];
// 订阅专题
    _subscribeSubjectButon = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _subscribeSubjectButon.frame = CGRectMake(_subscribeContentButton.right + 15, 0, _subscribeContentButton.width, _subscribeContentButton.height);
    [_subscribeSubjectButon setTitle:@"订阅专题" forState:(UIControlStateNormal)];
    // 添加点击方法
    [_subscribeSubjectButon addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    _subscribeSubjectButon.tag = 101;
    [_subscribeSubjectButon setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    //_subscribeSubjectButon.backgroundColor = [UIColor purpleColor];
    _subscribeSubjectButon.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [_titleView addSubview:_subscribeSubjectButon];
}
#pragma mark----------------标签按钮点击方法---------------
- (void)buttonAction:(UIButton *)button{
    // 判断是否与 之前点击的相同
    if (_numTag == button.tag) {
        
    }else{
    // 改变偏移量
        [self.scrollView setContentOffset:CGPointMake((button.tag - 100) * kScreenWidth, 0) animated:YES];
        _numTag = button.tag;
    }
}
#pragma mark----------------从数据库拿到数据------------
- (void)getDataFromDB{
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;

// 拼接路径
    NSString *pathString = [[path stringByAppendingPathComponent:@"data"]stringByAppendingPathComponent:@"GSDataBase.db"];
    NSLog(@"数据库路径==%@",pathString);
    _db = [FMDatabase databaseWithPath:pathString];
    if (![_db open]) {
        NSLog(@"数据打开失败");
    }


// 取出数据
    [self.dataArray removeAllObjects];
    [self.modelArray removeAllObjects];
    FMResultSet *resultSet = [_db executeQuery:@"select * from SubscribeList"];
    while ([resultSet next]) {
        NSString *nodeIds = [resultSet stringForColumn:@"nodeIds"];
        [self.dataArray addObject:nodeIds];
        NSNumber *cnt = [NSNumber numberWithInt:[resultSet intForColumn:@"cnt"]];
        NSString *sourceName = [resultSet stringForColumn:@"sourceName"];
        NSData *imageData = [resultSet dataForColumn:@"imageData"];
        GSSubscrebe_Add_Topic *model = [[GSSubscrebe_Add_Topic alloc] init];
        model.sourceName = sourceName;
        model.imageModel = [UIImage imageWithData:imageData];
        model.sourceId = nodeIds;
        model.cnt = cnt;
        model.isSubscribe = YES;
        [self.modelArray addObject:model];
    }
}
#pragma mark----------------数据源数组懒加载-------------
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
        return _dataArray;
}
- (NSMutableArray *)modelArray{
    if (!_modelArray) {
        _modelArray = [NSMutableArray array];
    }
    return _modelArray;
}
- (NSMutableArray *)subscribeContentTableViewListArray{
    if (!_subscribeContentTableViewListArray) {
        _subscribeContentTableViewListArray = [NSMutableArray array];
    }
    return _subscribeContentTableViewListArray;
}
- (NSMutableArray *)subscribeSubjectTableViewListArray{
if (!_subscribeSubjectTableViewListArray) {
        _subscribeSubjectTableViewListArray = [NSMutableArray array];
    }
    return _subscribeSubjectTableViewListArray;
}
#pragma mark----------------解析数据---------------------
// 订阅内容界面数据加载
- (void)setUpSubscribeContentTableViewData{
        // 构建参数字典的 nodeIds 对应的Value值
        NSString *nodeIds = [self.dataArray componentsJoinedByString:@","];
    // 构建参数字典
        NSDictionary *dic = @{@"request":@{@"parentNodeId":@"dingYue",
                                           @"nodeIds":nodeIds,
                                           @"type":@"newsList",
                                           @"pageIndex":[NSString stringWithFormat:@"%ld",_startIndexContent],
                                           @"elementsCountPerPage":@"20"}
                              };
    [GSNetworkManager requestWithUrlStr:Subscribe_Add_Topic_Details paraDict:dic method:POST success:^(NSURLResponse *response, NSData *data) {
        if (data) {
            NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:nil];
            if (_startIndexContent == 1) {
                [self.subscribeContentTableViewListArray removeAllObjects];
            }
            // 取出 有用数据
            NSArray *array = dic[@"result"];
            for (NSDictionary *oneDic in array) {
                GSSubscrebe_Add_Topic_Details *model = [[GSSubscrebe_Add_Topic_Details alloc] init];
                [model setValuesForKeysWithDictionary:oneDic];
                [self.subscribeContentTableViewListArray addObject:model];
            }
           // 展示页面 刷新
            // 结束 下拉刷新 上拉刷新
            [self.subscribeContentTableView.mj_header endRefreshing];
            [self.subscribeContentTableView.mj_footer endRefreshing];
            [_subscribeContentTableView reloadData];
        }
    } failure:^(NSError *error) {
    }];
}
// 订阅专题界面
- (void)setUpSubscribeSubjectTableViewData{
    // 构建参数字典的 nodeIds 对应的Value值
    NSString *nodeIds = [self.dataArray componentsJoinedByString:@","];
    
    // 构建参数字典
    NSDictionary *dic = @{@"request":@{@"parentNodeId":@"dingYue",
                                       @"nodeIds":nodeIds,
                                       @"type":@"dingyueTopic",
                                       @"lastUpdateTime":@0,
                                       @"pageIndex":@"1",
                                       @"elementsCountPerPage":@"20"}
                          };
    [GSNetworkManager requestWithUrlStr:Subscribe_Add_Topic_Details paraDict:dic method:POST success:^(NSURLResponse *response, NSData *data) {
        if (data) {
            NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:nil];
            [self.subscribeSubjectTableViewListArray removeAllObjects];
            // 获取数组
            NSArray *array = [dic objectForKey:@"result"];
            for (NSDictionary *dict in array) {
                GSSubscrebe_Add_Topic_Details *model = [[GSSubscrebe_Add_Topic_Details alloc] init];
                [model setValuesForKeysWithDictionary:dict];
                [self.subscribeSubjectTableViewListArray addObject:model];
            }
            // 结束刷新
            [self.subscribeSubjectTableView.mj_header endRefreshing];
            // 刷新界面
            [_subscribeSubjectTableView reloadData];
        }
    } failure:^(NSError *error) {
    }];

}
#pragma mark----------------添加scrollView---------------
- (void)addScrollView{
//    改变自适应
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight - 64 - 49)];
    self.scrollView.delegate = self;
    self.scrollView.bounces = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.alwaysBounceHorizontal = YES;
    self.scrollView.alwaysBounceVertical = NO;
    self.scrollView.contentSize = CGSizeMake(kScreenWidth * 2, self.scrollView.height);
    [self.view addSubview:self.scrollView];
}
#pragma mark----------------scrollView添加子视图---------------
- (void)addSubviewsOnScrollView{
    for (int i = 0; i < 2; i++) {

        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 + (kScreenWidth * i), -42, kScreenWidth, self.scrollView.height + 42) style:(UITableViewStylePlain)];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tag = 10 + i;
        
// 添加  表头
        UIView *search = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 42)];
        UIButton *searchBtn = [GSBorderButton buttonWithType:(UIButtonTypeCustom)];
        searchBtn.frame = CGRectMake(10, (42 - 30) / 2,kScreenWidth - 20, 30);
        searchBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [searchBtn setTitle:@"搜索" forState:(UIControlStateNormal)];
        [searchBtn setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [searchBtn setImage:[UIImage imageNamed:@"common_Icon_Search_20x20_UIMode_Day"] forState:(UIControlStateNormal)];
        [search addSubview:searchBtn];
        searchBtn.userInteractionEnabled = NO;
        
        tableView.tableHeaderView = search;
        
// 搜索框  添加手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [search addGestureRecognizer:tap];
        
        
        
        // 设置cell的高度
        tableView.rowHeight = kScreenWidth * 0.225;
        [self.scrollView addSubview:tableView];
  
    }
// 订阅内容界面
    _subscribeContentTableView = (UITableView *)[self.scrollView viewWithTag:10];
    //_subscribeContentTableView.backgroundColor = [UIColor purpleColor];
    // 订阅内容 界面  添加 下拉刷新
    self.subscribeContentTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        _startIndexContent = 1;
        [self setUpSubscribeContentTableViewData];
    }];
    // 订阅内容界面 添加 上提加载
    self.subscribeContentTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        _startIndexContent += 1;
        [self setUpSubscribeContentTableViewData];
    }];
    
// 订阅专题界面
    _subscribeSubjectTableView = (UITableView *)[self.scrollView viewWithTag:11];
    //_subscribeSubjectTableView.backgroundColor = [UIColor yellowColor];
   // 添加 下拉刷新
    self.subscribeSubjectTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self setUpSubscribeSubjectTableViewData];
    }];
    // 订阅界面 添加表尾
    // 添加 表尾
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenWidth, 48)];
    footerView.backgroundColor = [UIColor grayColor];
    UILabel *footLabel = [[UILabel alloc] initWithFrame:CGRectMake(6, 6, kScreenWidth - 12, 36)];
    footLabel.backgroundColor = [UIColor whiteColor];
    [footerView addSubview:footLabel];
    footLabel.textColor = [UIColor redColor];
    footLabel.textAlignment = NSTextAlignmentCenter;
    footLabel.text = @"添加更多订阅";
    // 表尾添加  轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [footerView addGestureRecognizer:tap];
    _subscribeSubjectTableView.tableFooterView = footerView;
}
#pragma mark-| 搜索框的 轻拍手势
- (void)tap:(UITapGestureRecognizer *)tap{

    GSSearchViewController *searchVC = [[GSSearchViewController alloc] init];
    searchVC.number = 1002;
    [self.navigationController pushViewController:searchVC animated:YES];
}
#pragma mark------------subscribeSubjectTableView表尾轻拍手势-----------
- (void)tapClick:(UITapGestureRecognizer *)tap{
// 跳转到 添加界面
    
    GSSubscribeViewController_Add *addVC = [[GSSubscribeViewController_Add alloc] init];
    [self.navigationController pushViewController:addVC animated:YES];

}
#pragma mark----------------tableView协议------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if ([tableView isEqual:_subscribeContentTableView]) {
        return 1;
    }else {
    
        return _subscribeSubjectTableViewListArray.count;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([tableView isEqual:_subscribeContentTableView]) {
        return self.subscribeContentTableViewListArray.count;
    }else {
        return 3;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:_subscribeContentTableView]) {
        static NSString *identifier = @"contentCell";
        GSSubscribeViewController_Add_Topic_Details_Cell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[GSSubscribeViewController_Add_Topic_Details_Cell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:identifier];
        }
// 取出 model
        if (_subscribeContentTableViewListArray.count != 0) {
            GSSubscrebe_Add_Topic_Details *model = _subscribeContentTableViewListArray[indexPath.row];
            cell.model = model;
        }
        return cell;
        
    }else{
    static NSString *cellTwo = @"subjectCell";
        GSSubscribeViewController_Add_Topic_Details_Cell *cell = [tableView dequeueReusableCellWithIdentifier:cellTwo];
        if (!cell) {
            cell = [[GSSubscribeViewController_Add_Topic_Details_Cell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:cellTwo];
        }
        // 取出大model
        if (_subscribeSubjectTableViewListArray.count != 0) {
            GSSubscrebe_Add_Topic_Details *model = _subscribeSubjectTableViewListArray[indexPath.section];
            // 获取 承载小model的 数组
            NSArray *modelArray = model.childElements;
            GSSubscrebe_Add_Topic_Details *modelUsing = modelArray[indexPath.row];
            cell.model = modelUsing;
        }
        return cell;
    }
}
// cell点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:_subscribeContentTableView]) {
        // 取出 model
        if (_subscribeContentTableViewListArray.count != 0) {
            GSSubscrebe_Add_Topic_Details *model = _subscribeContentTableViewListArray[indexPath.row];
            GSArticleViewController *articleVC = [[GSArticleViewController alloc] init];
            articleVC.contentID = model.contentId;
            [self.navigationController pushViewController:articleVC animated:YES];
        }
    }else{
        // 取出大model
        if (_subscribeSubjectTableViewListArray.count != 0) {
            GSSubscrebe_Add_Topic_Details *model = _subscribeSubjectTableViewListArray[indexPath.section];
            // 获取 承载小model的 数组
            NSArray *modelArray = model.childElements;
            GSSubscrebe_Add_Topic_Details *modelUsing = modelArray[indexPath.row];
            
            GSArticleViewController *articleVC = [[GSArticleViewController alloc] init];
            articleVC.contentID = modelUsing.contentId;
            [self.navigationController pushViewController:articleVC animated:YES];
            
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if ([tableView isEqual:_subscribeSubjectTableView]) {
        return 30;
    }
    return 0;
}
#pragma mark-----------------分区表头--------------------
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if ([tableView isEqual:_subscribeSubjectTableView]) {
        
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
        headerView.tag = section;
        //headerView.backgroundColor = [UIColor greenColor];
        // 添加轻拍手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAciton:)];
        [headerView addGestureRecognizer:tap];
        // 标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, headerView.width / 2, headerView.height)];
        titleLabel.textColor = [UIColor grayColor];
        //titleLabel.backgroundColor = [UIColor purpleColor];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont systemFontOfSize:14];
        [headerView addSubview:titleLabel];
        // 关注
        UILabel *attentionLabel = [[UILabel alloc] initWithFrame:CGRectMake(headerView.width - 110, 0, 80, headerView.height)];
        //attentionLabel.backgroundColor = [UIColor yellowColor];
        attentionLabel.textAlignment = NSTextAlignmentRight;
        attentionLabel.font = [UIFont systemFontOfSize:13];
        [headerView addSubview:attentionLabel];
        
        // 图片
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 30, 0, 30, headerView.height)];
        imageV.image = [UIImage imageNamed:@"qianjin"];
        [headerView addSubview:imageV];
        
        
// 赋值
    // 拿取对应model
        if (_subscribeSubjectTableViewListArray.count != 0) {
            GSSubscrebe_Add_Topic_Details *model = _subscribeSubjectTableViewListArray[section];
            titleLabel.text = model.title;
            attentionLabel.text = [NSString stringWithFormat:@"%@人关注",model.readingCount];
        }
        return headerView;
    }
    return nil;
}
#pragma mark---------------轻拍手势实现------------------
- (void)tapAciton:(UITapGestureRecognizer *)tap{
//  获取到 点击的view的tag
    NSInteger numTag = tap.view.tag;
    // 取出model
  GSSubscrebe_Add_Topic *model = self.modelArray[numTag];

    // 创建 请求字典, 添加 相应键值对, 传给下一个界面,方便 请求数据
    NSDictionary *dic = @{@"request":@{@"parentNodeId":@"dingYue",
                                       @"nodeIds":model.sourceId,
                                       @"type":@"dingyueList",
                                       @"pageIndex":@1,
                                       @"elementsCountPerPage":@20}
                          };
  
    
    // 创建,并赋属性
    GSSubscribeViewController_Add_Topic_Details *detailsVC = [[GSSubscribeViewController_Add_Topic_Details alloc] init];
    detailsVC.dic = dic;
    detailsVC.isSubscribe = YES;
    
    
    
    detailsVC.model = model;
    detailsVC.imageData = UIImagePNGRepresentation(model.imageModel);
    // 跳转
    [self.navigationController pushViewController:detailsVC animated:YES];
    
}
#pragma mark----------------scrollView协议--------------
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if ([scrollView isEqual:_scrollView]) {
        self.x = scrollView.contentOffset.x;
    }
    if ([scrollView isEqual:_subscribeContentTableView] || [scrollView isEqual:_subscribeSubjectTableView]) {
        // 保存 拖拽时的点
        self.y = scrollView.contentOffset.y;
    }
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if ([scrollView isEqual:_scrollView]) {
        CGFloat num = scrollView.contentOffset.x / kScreenWidth;
        _numTag = (int)100 + num;
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if ([scrollView isEqual:self.scrollView]) {
    int current = (int)_x / kScreenWidth + 0.5;
    CGFloat value = scrollView.contentOffset.x / kScreenWidth;
    // 变化倍数
    CGFloat scale = ABS(value - current) * 0.4;
    UIButton *currentButton = (UIButton *)[_titleView viewWithTag:100 + current];
    currentButton.titleLabel.font = [UIFont systemFontOfSize:14 * (1.4 - scale)];
    // 判断 方向
    // 向左滑动
    if (_x < scrollView.contentOffset.x) {
        UIButton *towardButton = (UIButton *)[_titleView viewWithTag:100 + current + 1];
        towardButton.titleLabel.font = [UIFont systemFontOfSize:14 * (1 + scale)];
    }else{
        // 向右滑
        UIButton *towardButton = (UIButton *)[_titleView viewWithTag:100 + current - 1];
        towardButton.titleLabel.font = [UIFont systemFontOfSize:14 * (1 + scale)];
    }
  }
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if ([scrollView isEqual:_subscribeContentTableView] || [scrollView isEqual:_subscribeSubjectTableView]) {
    // 利用保存的 点,  判断  滑动方法
    if (scrollView.contentOffset.y > _y) {
        // 上滑
        if (scrollView.contentOffset.y < 0) {
            // 若搜索框仍然  显示,将之 还原 (隐藏)
            [UIView beginAnimations:nil context:nil];
            [scrollView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
            [UIView commitAnimations];
        }
    }else{
        // 下滑
        if (scrollView.contentOffset.y < -10) {
            // 若 当前 点,滑动 幅度  大于  10,则 显示 搜索框
            [UIView beginAnimations:nil context:nil];
            [scrollView setContentInset:UIEdgeInsetsMake(42, 0, 0, 0)];
            [UIView commitAnimations];
        }else if (scrollView.contentOffset.y > -10 && scrollView.contentOffset.y < 0)
        {
            // 若 当前 滑动 幅度   小于10 ,则 继续 隐藏 搜索框
            [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        }
    }
}
}
#pragma mark----------------添加 按钮实现-------------------
// 跳转到  添加controller
- (void)rightAction:(UIBarButtonItem *)sender{
    
    GSSubscribeViewController_Add *addVC = [[GSSubscribeViewController_Add alloc] init];
    [self.navigationController pushViewController:addVC animated:YES];
}

#pragma mark---------------------------------------------
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
